package com.hhly.rabbitmq.topic;

import java.util.Random;

import com.hhly.rabbitmq.RabbitMQUtil;
import com.rabbitmq.client.Channel;
/**
 * 
 * @desc 订阅
 * @author jiangwei
 * @date 2017年3月24日
 * @company 益彩网络科技公司
 * @version 1.0
 */
public class EmitLogTopic {
	 static final String EXCHANGE_NAME = "topic_logs";
	
	 static  final String[] severity = {"test.error","info.hhly","warning.uuu.hhh"};
	
	public static void main(String[] args) throws Exception {
		Channel channel = RabbitMQUtil.getChannel();
	    channel.exchangeDeclare(EXCHANGE_NAME, "topic");
	    int i = 0;
	    Random random = new Random();
	    for(;;){
	    	Thread.sleep(1000);
	    	String message = "Hello World!"+ i++;
	    	String routing = severity[random.nextInt(severity.length)];
	 	    channel.basicPublish(EXCHANGE_NAME,routing , null, message.getBytes());
	 	    System.out.println(" [x] Sent '" + routing + "':'" + message + "'");
	    }
	}
}
